#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include "index.h"
#include "src/index_private.h"

#define MAX_OBJECTS 200000

typedef struct object_t {
    avl_node avl;
    int      id;
    int      color;
    int      group;
    int      width;
} object_t;

object_t object_pool[MAX_OBJECTS];

static int
object_comp(void *a, void *b, void *ctx)
{
    object_t *A = (object_t *)a;
    object_t *B = (object_t *)b;
    return A->id - B->id;
}

int main(int argc, char *argv[])
{
    int       i;
    object_t *object; 
    index_t  *index;

    index = index_new(MAX_OBJECTS, 3, NULL, NULL, 0);
    index_create_attribute(index, offsetof(object_t, color), sizeof(int));
    index_create_attribute(index, offsetof(object_t, group), sizeof(int));
    index_create_attribute(index, offsetof(object_t, width), sizeof(int));
    
    for (i = 0; i < MAX_OBJECTS; i++) {
        object = &object_pool[i];   
        object->id = i;
       
        object->color = 0; if (i % 2  == 0) object->color = i;
        object->group = 0; if (i % 3  == 0) object->group = i;
        object->width = 0; if (i % 47 == 0) object->width = i;

        index_insert(index, object, NULL);
    }

    for (i = 0; i < index->attr_count; i++) {
        index_attr *attr = &index->attributes[i];
        avl_tree *tree = attr->tree;
        printf("ATTRIBUTE: %d  SIZE: %d\n", i, avl_size(tree));   
    }

    return 0;
}

